//
//  RPAccountErrorView.m
//  ShowYork
//
//  Created by hxh on 2020/8/25.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "RPAccountErrorView.h"


@interface RPAccountErrorView ()
@property (nonatomic,copy)NSString *errorMessage;
@end


@implementation RPAccountErrorView


- (instancetype)initWithErrorMessage:(NSString *)errorMsg andCompleteBlock:(void (^)(void))completeBlock{
    if (self = [super init]) {
        self.errorMessage = errorMsg;
        [self setUI];
    }
    return self;
}

- (void)setUI{
    self.frame = CGRectMake(0, 0, kScreenW, kScreenH);
    self.backgroundColor = RGBA(0, 0, 0,0.3);
}

- (void)showIn:(UIViewController *)vc{
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:self.errorMessage preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [alertController dismissViewControllerAnimated:YES completion:nil];
        [self removeFromSuperview];
    }];
    //往alertViewController上添加alertAction
    [alertController addAction:confirmAction];
    
    [vc presentViewController:alertController animated:YES completion:nil];
}

@end
